/**
 * @author : cyb1010
 * @date   : 2024-06-13 08:10:59
 * @file   : bishop.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<pair<int, int>> vp;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
int __, n, m;
vp ans;
vp solve(int n, int m) {
    vp res;
    if (n > m) {
        res = solve(m, n);
        for (auto &[x, y] : res) swap(x, y);
        return res;
    }
    if (n & 1) {
        for (int i = 1; i <= n; i++)
            res.emplace_back(i, 1), res.emplace_back(i, m);
        int rw = n / 2 + 1;
        for (int i = rw + 1; i + rw <= m; i++) res.emplace_back(rw, i);
        return res;
    }
    for (int i = 1; i <= n; i++) res.emplace_back(i, 1), res.emplace_back(i, m);
    int rw = n / 2;
    for (int i = rw + 2; i + rw < m; i += 2)
        res.emplace_back(rw, i), res.emplace_back(rw + 1, i);
    return res;
}
int main() {
    fo("bishop");
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    if (n == m) {
        if (n == 1) return cout << "1\n1 1\n", 0;
        cout << n * 2 - 2 << '\n';
        for (int i = 1; i < n; i++)
            cout << i << " 1\n" << i << ' ' << n << '\n';
        return 0;
    }
    vp ans = solve(n, m);
    cout << SZ(ans) << '\n';
    for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
    return 0 ^ __ ^ 0;
}